﻿using HungryCrowdLibrary.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace HungryCrowdLibrary.Manager
{
    public class TraderManager
    {
        internal TraderData traderData;
        internal TraderData TraderData { get { return traderData = traderData ?? new TraderData(); } }

        #region Get and Save methods
        public bool SaveChanges(Trader trader)
        {
            var success = false;
            using(var hctx = new HungryCrowdEntities()) 
            {
                hctx.Traders.Add(trader);
                success = hctx.SaveChanges() > 0;
            }
            return success;
        }
       
        public List<Trader> GetList(Expression<Func<Trader,bool>> search)
        {
            return TraderData.GetList(search);
        }

        public Trader GetDetail(Expression<Func<Trader,bool>> search)
        {
            return TraderData.GetDetail(search);
        }
        #endregion
    }
}
